package com.api.common.manager;


import com.api.common.constant.APIInterfaceMqConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


/**
 * 发送接口日志到队列
 */
@Component
@Slf4j
public class APIGatewayAccessLogManager {

    @Resource
    private RabbitTemplate rabbitTemplate;


    public void sendMessage(String message){

        try {
            rabbitTemplate.convertAndSend(
                    APIInterfaceMqConstant.API_GATEWAY_ACCESS_LOG_EXCHANGE,
                    APIInterfaceMqConstant.API_GATEWAY_ACCESS_LOG_ROUTE_KEY,
                    message);
        }catch (Exception e){
            log.error("发送MQ消息失败: {}", message, e);
        }

    }
}
